package com.example.j2025_11_10.config;


import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;
@Slf4j
@Component
@Aspect
public class TimeAdvice {
    @Pointcut("execution(* com.example.j2025_11_10.controller.*.*(..))")
    public void pt(){
    }
//    @Before("pt()")
//    public void before(){
//        log.info("before.....");
//    }
//    @After("execution(* com.example.j2025_11_10.controller.*.*(..))")
//    public void after(){
//        log.info("after....");
//    }
//    @AfterReturning("execution(* com.example.j2025_11_10.controller.*.*(..))")
//    public void afterReturning(){
//        log.info("afterReturning....");
//    }
//    @AfterThrowing("execution(* com.example.j2025_11_10.controller.*.*(..))")
//    public void afterThrowing(){
//        log.info("afterThrowing.....");
//    }
    @Around("execution(* com.example.j2025_11_10.controller.*.*(..))")
    public Object recordTime(ProceedingJoinPoint pjp) throws Throwable {
        //记录开始时间
        long begin = System.currentTimeMillis();
        //执行方法
        Object result = pjp.proceed();
        //记录结束时间
        long end = System.currentTimeMillis();
        //打印耗时
        log.info(pjp.getSignature() + "执⾏耗时: {}ms", end - begin);
        return result;
    }
}
